package com.stylefeng.guns.modular.clm.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ClmRoomCourseware;
import com.stylefeng.guns.modular.clm.service.IClmRoomCoursewareService;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-04-04 16:54:39
 */
@Controller
@RequestMapping("/clmRoomCourseware")
public class ClmRoomCoursewareController extends BaseController {

    private String PREFIX = "/clm/clmRoomCourseware/";

    @Autowired
    private IClmRoomCoursewareService clmRoomCoursewareService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "clmRoomCourseware.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/clmRoomCourseware_add")
    public String clmRoomCoursewareAdd() {
        return PREFIX + "clmRoomCourseware_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/clmRoomCourseware_update/{clmRoomCoursewareId}")
    public String clmRoomCoursewareUpdate(@PathVariable Integer clmRoomCoursewareId, Model model) {
        ClmRoomCourseware clmRoomCourseware = clmRoomCoursewareService.selectById(clmRoomCoursewareId);
        model.addAttribute("item",clmRoomCourseware);
        LogObjectHolder.me().set(clmRoomCourseware);
        return PREFIX + "clmRoomCourseware_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return clmRoomCoursewareService.selectList(null);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ClmRoomCourseware clmRoomCourseware) {
        clmRoomCoursewareService.insert(clmRoomCourseware);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer clmRoomCoursewareId) {
        clmRoomCoursewareService.deleteById(clmRoomCoursewareId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ClmRoomCourseware clmRoomCourseware) {
        clmRoomCoursewareService.updateById(clmRoomCourseware);
        return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{clmRoomCoursewareId}")
    @ResponseBody
    public Object detail(@PathVariable("clmRoomCoursewareId") Integer clmRoomCoursewareId) {
        return clmRoomCoursewareService.selectById(clmRoomCoursewareId);
    }
}
